package com.furongji.education.service.impl;

import com.furongji.common.domain.vo.VideoPlayPageVo;
import com.furongji.common.exception.MyException;
import com.furongji.education.clients.CourseFeignClient;
import com.furongji.education.service.AliyunVodService;
import com.furongji.education.utils.AliyunVodOperator;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@RequiredArgsConstructor
public class AliyunVodServiceImpl implements AliyunVodService {

    private final AliyunVodOperator aliyunVodOperator;

    private final CourseFeignClient courseClient;

    @Override
    public VideoPlayPageVo getVideoAuthInfo(String videoId) {
        if (StringUtils.isEmpty(videoId)) {
            throw new MyException(200001, "视频凭证不能为空");
        }
        VideoPlayPageVo courseInfoWithSections = courseClient.getCourseInfoWithSections(videoId);
        if (courseInfoWithSections == null) {
            throw new MyException(20001, "获取视频凭证失败");
        }
        String videoAuth = aliyunVodOperator.getVideoAuth(videoId);
        if (videoAuth == null) {
            throw new MyException(20001, "视频凭证为空");
        }
        courseInfoWithSections.setVideoAuth(videoAuth);
        return courseInfoWithSections;
    }
}
